/*
 * QE3e Qt Quick 3D Engine.
 * Copyright (C) 2010 Joris Vaillant and Mathieu Pujol 
 * <joris.vaillant@gmail.com>  <mathieu.pujol87@gmail.com>
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */


#ifndef TEXTUREMANAGER_H
#define TEXTUREMANAGER_H

//qe3e
#include <qe3e_global.h>
#include <Texture.h>

//Qt
#include <QHash>
#include <QMutex>

namespace qe3e
{
  class  TextureManager
  {
  public:
    QE3E_EXPORT static TextureManager * getInstance();

    QE3E_EXPORT static void destroy();

    QE3E_EXPORT void clear();

    QE3E_EXPORT Texture getTexture2D(const QString & fileName,
                                     Texture::TextureType type = Texture::diffuse,
                                     bool forceReloadAndMemorySeparation=false);

    void incUseCptr(GLuint texId);
    void decUseCptr(GLuint texId);

  private:
    TextureManager();
    ~TextureManager();

    void destroyTexture(GLuint texId);
    void loadTexture2D(const QString & fileName, GLuint texId);

    static TextureManager * mInstance;

    QHash<QString, GLuint> mFileHash;
    QHash<GLuint, int> mUseCpt;

    QMutex mMutex;
  };
}
#endif // TEXTUREMANAGER_H
